package com.minigame.card.mahjong.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashSet;
import java.util.Set;

@AllArgsConstructor
@Getter
public enum MahjongCard {
    W1(0, '万', "一万"),
    W2(1, '万', "二万", true),
    W3(2, '万', "三万"),
    W4(3, '万', "四万"),
    W5(4, '万', "五万", true),
    W6(5, '万', "六万"),
    W7(6, '万', "七万"),
    W8(7, '万', "八万", true),
    W9(8, '万', "九万"),

    T1(9, '条', "一条"),
    T2(10, '条', "二条", true),
    T3(11, '条', "三条"),
    T4(12, '条', "四条"),
    T5(13, '条', "五条", true),
    T6(14, '条', "六条"),
    T7(15, '条', "七条"),
    T8(16, '条', "八条", true),
    T9(17, '条', "九条"),

    B1(18, '饼', "一饼"),
    B2(19, '饼', "二饼", true),
    B3(20, '饼', "三饼"),
    B4(21, '饼', "四饼"),
    B5(22, '饼', "五饼", true),
    B6(23, '饼', "六饼"),
    B7(24, '饼', "七饼"),
    B8(25, '饼', "八饼", true),
    B9(26, '饼', "九饼"),

    DF(27, '风', "东风", true, false),
    NF(28, '风', "南风", true, false),
    XF(29, '风', "西风", true, false),
    BF(30, '风', "北风", true, false),
    HZ(31, '风', "红中", true, false),
    FC(32, '风', "发财", true, false),
    BB(33, '风', "白板", true, false),
    ;
    private final int index;
    private final char type;
    private final String name;
    private final boolean feng;
    private final boolean jiang;

    MahjongCard(int index, char type, String name) {
        this.index = index;
        this.type = type;
        this.name = name;
        this.feng = false;
        this.jiang = false;
    }

    MahjongCard(int index, char type, String name, boolean jiang) {
        this.index = index;
        this.type = type;
        this.name = name;
        this.feng = false;
        this.jiang = jiang;
    }

    public static MahjongCard ofIndex(int index) {
        for (MahjongCard value : values()) {
            if (value.index == index) {
                return value;
            }
        }
        return null;
    }

    public static Set<Integer> indexSetOfJiang() {
        Set<Integer> set = new HashSet<>();
        for (MahjongCard value : values()) {
            if (value.isJiang()) {
                set.add(value.index);
            }
        }
        return set;
    }

    public static Set<Integer> indexSetOfType(char type) {
        Set<Integer> set = new HashSet<>();
        for (MahjongCard value : values()) {
            if (value.type == type) {
                set.add(value.index);
            }
        }
        return set;
    }

    public static final Set<Integer> JIANG_INDEXES = indexSetOfJiang();
    public static final Set<Integer> WAN_INDEXES = indexSetOfType('万');
    public static final Set<Integer> TIAO_INDEXES = indexSetOfType('条');
    public static final Set<Integer> BING_INDEXES = indexSetOfType('饼');
    public static final Set<Integer> FENG_INDEXES = indexSetOfType('风');
}
